package logs

import (
	"fmt"
	"github.com/fatih/color"
	"github.com/gin-gonic/gin"
	"ruoyi-hello/config"
	"time"
)

// get 方法写入log 文档里面
// post put del 方法 写入数据库
// 错误日志写入数据库
func Logger() gin.HandlerFunc {
	if !config.Config.Log.Enabled {
		return gin.Logger()
	}
	return gin.LoggerWithFormatter(func(params gin.LogFormatterParams) string {
		return fmt.Sprintf("%s - [%s] \"%s %s %s %d %s \"%s\" %s\"\n",
			params.ClientIP,
			params.TimeStamp.Format(time.RFC1123),
			params.Method,
			params.Path,
			params.Request.Proto,
			params.StatusCode,
			params.Latency,
			params.Request.UserAgent(),
			params.ErrorMessage,
		)
	})
}

func Poster() {
	fg := color.New(color.FgBlue)
	logo := `
  _____                            _                     
 |  __ \                          (_)                 
 | |__) |  _   _    ___    _   _   _    
 |  _  /  | | | |  / _ \  | | | | | | 
 | | \ \  | |_| | | (_) | | |_| | | |          
 |_|  \_\  \__,_|  \___/   \__, | |_|           
                            __/ |                              
                           |___/                               
`
	fg.Println(logo)
}
